#!/bin/bash

LEMONPATH="./lemonphp/"

if [ $# -ne 1 ]; then
    echo "Usage: `basename $0` {parser_file}"
    exit 1
fi

FILENAME=$1

TEMPFILE=`mktemp`
TEMPFILENAME=`basename $TEMPFILE`
cat $LEMONPATH/Main.php-cut > $TEMPFILE
GRAMMARFILE=`realpath $1`

echo '$_SERVER'"['argv'] = array('lemon', '-s', '"$GRAMMARFILE"');" >> $TEMPFILE
echo '$a->main();' >> $TEMPFILE
echo "Processing file: $GRAMMARFILE"
echo "Temp file: $TEMPFILE"
echo "Temp file name: $TEMPFILENAME"

mv $TEMPFILE $LEMONPATH
php $LEMONPATH$TEMPFILENAME
rm $LEMONPATH$TEMPFILENAME

GRAMMARPHP=${GRAMMARFILE:0:${#GRAMMARFILE}-2}

mv $GRAMMARPHP.php ../../langs_code/system/`basename $GRAMMARPHP.php`
rm $GRAMMARPHP.out


